<?php
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @see http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */

/*
 * 用于检测业务代码死循环或者长时间阻塞等问题
 * 如果发现业务卡死，可以将下面declare打开（去掉//注释），并执行php start.php reload
 * 然后观察一段时间workerman.log看是否有process_timeout异常
 */
//declare(ticks=1);
use \GatewayWorker\Lib\Gateway;
class Events
{
    /**
     * 当客户端发来消息时触发.
     * @param  int       $client_id 连接id
     * @param  mixed     $message   具体消息
     * @throws Exception
     */
    public static function onMessage($client_id, $message): void
    {
        echo "client_id: {$client_id} send message: $message".PHP_EOL;
        $message = "client_id: {$client_id} ---- hello test";
        GateWay::sendToClient($client_id, $message);
    }

    /**
     * 当客户端断开连接时触发.
     * @param $client_id
     * @throws \Exception
     */
    public static function onClose($client_id): void
    {
    }

    /**
     * 当businessWorker进程退出时触发.
     * @param $businessWorker
     * @throws Exception
     */
    public static function onWorkerStop($businessWorker): void
    {
    }
}
